﻿using System;
using System.Linq;
using Wicresoft.EKA.MVCExtensions;
using Wicresoft.EKA.ITSM.Business;
using System.Collections.Generic;

namespace Wicresoft.EKA.ITSM.BusinessImpl
{
    public class SMGXJPlanTaskFrame : Base, ISMGXJPlanTaskFrame
    {
        int BugCounts = Convert.ToInt32(System.Web.Configuration.WebConfigurationManager.AppSettings["BugCount"]);
        protected override void Dispose(bool disposing)
        {
        }

        public object CreateFrame(SMGXJPlanTaskFrameModel model)
        {
            try
            {
                var proxy = this.GetARProxy<SMGXJPlanTaskFrameModel>();
                proxy.CreateEntry(model);
            }
            catch (Exception e)
            {
                return "Fail :" + e.Message;
            }
            return "Success";
        }

        public SMGXJPlanTaskFrameModel GetFrame(string Qual)
        {
            var proxy = this.GetARProxy<SMGXJPlanTaskFrameModel>();
            var list = proxy.GetListEntry(Qual, new List<uint> { 
                SMGXJPlanTaskFrameModel.RequestID_ID,
                SMGXJPlanTaskFrameModel.TcChr_FullName_ID,
                SMGXJPlanTaskFrameModel.TcChr_Name_ID,
                SMGXJPlanTaskFrameModel.TcChr_Office_ID,
                SMGXJPlanTaskFrameModel.TcChr_TicketID_ID,
                SMGXJPlanTaskFrameModel.TcChr_Department_ID,
                SMGXJPlanTaskFrameModel.TcChr_Description_ID,
                SMGXJPlanTaskFrameModel.TcChr_MarkAsDelete_ID,
                SMGXJPlanTaskFrameModel.TaskID_ID,
                SMGXJPlanTaskFrameModel.CreateDate_ID,
                SMGXJPlanTaskFrameModel.cDat_ExpiredTiem_ID,
                SMGXJPlanTaskFrameModel.cDat_TicketTime_ID,
                SMGXJPlanTaskFrameModel.cChr_AssignStation_ID,
                SMGXJPlanTaskFrameModel.ModifiedDate_ID,
                SMGXJPlanTaskFrameModel.Status_ID,
                SMGXJPlanTaskFrameModel.cChr_TicketName_ID,
                SMGXJPlanTaskFrameModel.cChr_officeName_ID
            }).FirstOrDefault();
            return list;
        }

        public List<SMGXJPlanTaskFrameModel> GetFrameList(string Qual)
        {
            var proxy = this.GetARProxy<SMGXJPlanTaskFrameModel>();
            var list = proxy.GetListEntry(Qual, new List<uint> { 
                SMGXJPlanTaskFrameModel.RequestID_ID,
                SMGXJPlanTaskFrameModel.TcChr_FullName_ID,
                SMGXJPlanTaskFrameModel.TcChr_Name_ID,
                SMGXJPlanTaskFrameModel.TcChr_Office_ID,
                SMGXJPlanTaskFrameModel.TcChr_TicketID_ID,
                SMGXJPlanTaskFrameModel.TcChr_Department_ID,
                SMGXJPlanTaskFrameModel.TcChr_Description_ID,
                SMGXJPlanTaskFrameModel.TcChr_MarkAsDelete_ID,
                SMGXJPlanTaskFrameModel.TaskID_ID,
                SMGXJPlanTaskFrameModel.CreateDate_ID,
                SMGXJPlanTaskFrameModel.cDat_TicketTime_ID,
                SMGXJPlanTaskFrameModel.ModifiedDate_ID,
                SMGXJPlanTaskFrameModel.Status_ID,
                SMGXJPlanTaskFrameModel.cChr_TicketName_ID,
                SMGXJPlanTaskFrameModel.cChr_officeName_ID,
                SMGXJPlanTaskFrameModel.cChr_Status_ID
            }).ToList();
            return list;
        }

        public List<SMGXJPlanTaskFrameModel> GetFrameByList(string Qual)
        {
            var proxy = this.GetARProxy<SMGXJPlanTaskFrameModel>();
            var list = proxy.GetListEntry(Qual, new List<uint> { 
                SMGXJPlanTaskFrameModel.TcChr_FullName_ID,
                SMGXJPlanTaskFrameModel.TcChr_Name_ID,
                SMGXJPlanTaskFrameModel.TcChr_Office_ID,
                SMGXJPlanTaskFrameModel.TcChr_TicketID_ID,
                SMGXJPlanTaskFrameModel.TcChr_Department_ID,
                SMGXJPlanTaskFrameModel.TcChr_Description_ID,
                SMGXJPlanTaskFrameModel.TcChr_MarkAsDelete_ID,
                SMGXJPlanTaskFrameModel.TaskID_ID,
                SMGXJPlanTaskFrameModel.CreateDate_ID,
                SMGXJPlanTaskFrameModel.cDat_TicketTime_ID,
                SMGXJPlanTaskFrameModel.ModifiedDate_ID,
                SMGXJPlanTaskFrameModel.Status_ID,
                SMGXJPlanTaskFrameModel.cChr_TicketName_ID,
                SMGXJPlanTaskFrameModel.cChr_officeName_ID,
                SMGXJPlanTaskFrameModel.cChr_Status_ID
            }).OrderByDescending(T => T.CreateDate).Take(BugCounts).ToList();
            return list;
        }
        public string Modify(string Qual ,SMGXJPlanTaskFrameModel model)
        {
            try
            {
                var proxy = this.GetARProxy<SMGXJPlanTaskFrameModel>();
                proxy.SetEntryByQuery(model, Qual, BMC.ARSystem.Server.SetEntryByQuery_NoMatchOption.NoAction, BMC.ARSystem.Server.SetEntryByQuery_MultiMatchOption.ModifyFirst);
            }
            catch (Exception e)
            {
                return "Fail :" + e.Message;
            }
            return "Success";
        }
    }
}
